package com.crowntit.domain.trade.service.settlement.filter;

import com.crowntit.domain.trade.adapter.repository.ITradeRepository;
import com.crowntit.domain.trade.model.entity.TradeSettlementRuleBackEntity;
import com.crowntit.domain.trade.model.entity.TradeSettlementRuleCommandEntity;
import com.crowntit.domain.trade.service.settlement.factory.TradeSettlementRuleFilterFactory;
import com.crowntit.types.design.framework.link.model2.handler.ILogicHandler;
import com.crowntit.types.enums.ResponseCode;
import com.crowntit.types.exception.AppException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class TradeSettlementScInterceptRuleFilter implements ILogicHandler<TradeSettlementRuleCommandEntity, TradeSettlementRuleFilterFactory.DynamicContext, TradeSettlementRuleBackEntity> {

    @Resource
    private ITradeRepository repository;

    @Override
    public TradeSettlementRuleBackEntity apply(TradeSettlementRuleCommandEntity requestParam, TradeSettlementRuleFilterFactory.DynamicContext dynamicContext) throws Exception {
        log.info("sc黑名单检测");
        if (repository.isScIntercept(requestParam.getSource(), requestParam.getChannel())) {
            throw new AppException(ResponseCode.E0105.getCode(), ResponseCode.E0105.getInfo());
        }
        return next(requestParam, dynamicContext);
    }
}
